﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Web;

namespace SaturniLibrary.Web
{
    public static class UtilityExtension
    {
        public static string ToQueryString(this NameValueCollection query)
        {
            if (query == null)
            {
                return "";
            }

            if (!query.HasKeys())
            {
                return "";
            }

            StringBuilder sb = new StringBuilder();
            foreach (string key in query.Keys)
            {
                sb.AppendFormat("&{0}={1}", key, HttpUtility.UrlPathEncode(query[key]));
            }
            return sb.ToString(1, sb.Length - 1);
        }
    }
}
